﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="ListA.aspx.cs" Inherits="cebao.Web.userinfo.ListA" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Script/sitedata.js"></script>
    <script src="../Script/city.js"></script>
    <script src="../Script/combobox.js"></script>
    <script src="../Script/prositedata.js"></script>
    <script src="../Script/username.js"></script>    
    <style>
        html, body {
            height:100%
        } 
    </style>
    <script type="text/javascript">
        var advtype = [{ "id": "-1", "text": "省级代理商", "selected": true }, { "id": "4", "text": "国家级用户" }, { "id": "3", "text": "省级用户" }, { "id": "2", "text": "市级用户" }, { "id": "1", "text": "县级用户" }, { "id": "0", "text": "普通用户" }];
        var citytype = [{ "id": "3", "text": "省级用户", "selected": true }, { "id": "2", "text": "市级用户" }, { "id": "1", "text": "县级用户" }, { "id": "0", "text": "普通用户" }];
        
        var provinceName;
        var cityName;
        var arrCity;
        var areaName;
        var arrArea;
        $.extend($.fn.tree.methods, {
            getLevel:function(jq,target){
                var l = $(target).parentsUntil("ul.tree","ul");
                return l.length+1;
            }
        });
        $(function () {
            InitTree();
            InitGird();
            InitSearch();
            loadName();
            InitLevel();
        });
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度                
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyarea" },
                onBeforeExpand: function (node) {
                    $("#pt").tree("options").queryParams = { "action": "queryyb" };
                    $('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        var lv = $('#pt').tree("getLevel", node.target);
                        var bm = node.bm;
                        $('#spro').val("");
                        $('#scity').val("");
                        $('#scou').val("");
                        if (lv == 1)
                        {
                            $('#spro').val(node.text);
                        }
                        if (lv == 2)
                        {
                            $('#scity').val(node.text);
                            $('#spro').val($('#pt').tree("getParent", node.target).text);
                        }
                        if (lv == 3)
                        {
                            $('#scou').val(node.text);
                            var node1=$('#pt').tree("getParent", node.target)
                            $('#scity').val(node1.text);
                            $('#spro').val($('#pt').tree("getParent", node1.target).text);
                        }
                        reloadgrid()
                    }
                },
                onLoadSuccess: function (node, param) {
                    //$('#pt').tree("collapseAll");
                }
            });
        }
        function getQueryParams(queryParams) {
            var sprovince = $("#spro").val();
            var scity = $("#scity").val();
            var scounty = $("#scou").val();
            queryParams.spro = sprovince;
            queryParams.scity = scity;            
            queryParams.scou = scounty;            
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {

            //查询参数直接添加在queryParams中      
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');

        }
            
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '用户列表', //表格标题
                url: 'GetUser.ashx', //请求数据的页面
                sortName: 'uname', //排序字段
                idField: 'uid', //标识字段,主键
                iconCls: '', //标题左边的图标
                //width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: false,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
	                { title: '用户名', field: 'uname', width: 100, sortable: true },
                    { title: '职务', field: 'pname', width: 150 },
                    { title: '测报站名称', field: 'uunit', width: 150 },
                    { title: '联系电话', field: 'utel', width: 100 },
                    { title: '单位邮箱', field: 'uemail', width: 150 },
                    { title: '负责人姓名', field: 'utruename', width: 80 },
                    { title: '手机', field: 'uphone', width: 80 },
                    { title: '单位地址', field: 'madd', width: 250 },
                    {
                        title: '用户权限等级', field: 'ulevel', width: 100, formatter: function (value, row, index) {
                            if (value == 0) {
                                return "普通用户";
                            } else if (value == 1) {
                                return "县级用户";
                            } else if (value ==2) {
                                return "市级用户";
                            } else if (value == 3) {
                                return "省级用户";
                            } else if (value == 4) {
                                return "全国用户";
                            } else if (value == 5) {
                                return "管理员";
                            } else if (value == -1) {
                                return "省级代理商";
                            }
                        }
                    },
                    { title: '小气候设备', field: 'remark', width: 100 }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querya" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        function InitLevel() {
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    $('#level').val(data[0].level);
                    if (data[0].level == -1) {
                        $("#ulevel").combobox({
                            required: true,
                            panelHeight: 'auto',
                            data:citytype,
                            editable: false,
                            valueField:'id',    
                            textField:'text',   
                            onChange: setLevel
                        });
                       
                    }
                    if (data[0].level == 5) {
                        $("#ulevel").combobox({
                            required: true,
                            data:advtype,
                            panelHeight: 'auto',
                            editable: false,
                            valueField: 'id',
                            textField: 'text',
                            onChange: setLevel
                        });
                        
                    }
                   
                }
            });
                      
        }
        function setLevel(newValue, oldValue)
        {
            var value = $('#ulevel').combobox('getValue');
            switch (value) {
                case "2":
                    $("#dcounty").hide();
                    $('#ucounty').combobox('setValue', '');
                    $("#dcity").show();
                    $("#dprovince").show();
                    break;
                case "3":
                    $("#dcity").hide();
                    $('#ucity').combobox('setValue', '');
                    $("#dcounty").hide();
                    $('#ucounty').combobox('setValue', '');
                    $("#dprovince").show();
                    break;
                case "4":
                    $("#dcity").hide();
                    $('#ucity').combobox('setValue', '');
                    $("#dcounty").hide();
                    $('#ucounty').combobox('setValue', '');
                    $("#dprovince").hide();
                    $('#uprovince').combobox('setValue', '');
                    break;
                case "-1":
                    $("#dcity").hide();
                    $('#ucity').combobox('setValue', '');
                    $("#dcounty").hide();
                    $('#ucounty').combobox('setValue', '');
                    $("#dprovince").show();
                    break;
                default:
                    $("#dcity").show();
                    $("#dcounty").show();
                    $("#dprovince").show();
                    break;
            }

        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
            $('#pid').combobox({
                url: '../postinfo/GetPost.ashx?action=ddllist',
                valueField: 'pid',
                textField: 'pname',
                panelHeight: 'auto',
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#pid').combobox('getData');
                    if (data.length > 0)
                        $("#pid").combobox('select', data[0].pid);
                }
            });
        }
        function newUser() {            
            $('#fm').form('clear');                       
            $('#ulevel').combobox('setValue', '3');
            $('#dlg').dialog('open').dialog('setTitle', '添加管理员');
            $("#upwd").validatebox({
                required:true,
                missingMessage: '必填项'
            });
            document.getElementById("test").value = "adda";
        }
        //修改管理员  
        function editUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }        
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改管理员');
                $('#uid').val(row.uid);
                document.getElementById("test").value = "modifya";
                $("#uname").validatebox({    
                    required: true,    
                    validType: 'loginName[3,"'+row.uname+'"]'   
                });
                $('#pwd').val(row.upwd);
                
                $("#upwd").validatebox({
                    required: false,
                    missingMessage:'不填写为原始值'
                });
                $('#fm').form('load', row);
                setLevel(null, null);
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "adda") {
                f.form('submit', {
                    url: "GetUser.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {

                $('#fm').form('submit', {
                    url: "GetUser.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }
        function getids(rows) {
            var ids = "";
            for (var i = 0; i < rows.length; i++)
                ids = ids + rows[i].uid + ",";
            if (ids != "")
                ids = ids.substr(0, ids.length - 1);
            return ids;

        }
        function removeUser() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (rows) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    var ids = getids(rows);
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetUser.ashx?uids=' + ids + "&action=deletes",
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");                                     
                                    $('#tt').datagrid('reload');
                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width:100%; height:100%;" id="mycon">
        <div region="west" split="true" title="区域检索" style="width: 180px;overflow:scroll" id="west">
            <ul id="pt"></ul>
        </div>
        <div region="center" style="background: #eee; overflow-y: hidden">
            <table id="tt">
            </table>
        </div>


        <div id="tab_toolbar" style="padding: 4px;">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>

                    <td style="padding-left: 2px">


                        <a href="#" onclick="newUser();" id="a_add"
                            class="easyui-linkbutton" iconcls="icon-add">添加</a>
                        <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                        <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                    </td>
                    <td style="text-align: right; padding-right: 15px">
                        <input id="ipt_search" menu="#search_menu" />
                        <div id="search_menu" style="width: 120px">
                            <div name="usernum">
                                用户名
                            </div>
                            <div name="username">
                                姓 名
                            </div>
                        </div>
                    </td>
                </tr>
            </table>

        </div>
        <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
            data-options="closed:true,buttons:'#dlg-buttons',shadow:false">

            <form id="fm" method="post">

                <div class="fitem">
                    <label>用户名：</label>
                    <input id="uname" name="uname" class="easyui-validatebox" data-options="required:true,validType:'loginName[3]'" />
                </div>
                <div class="fitem">
                    <label>密码：</label>
                    <input id="upwd" name="upwd" type="password" class="easyui-validatebox" data-options="required:true" />
                    <input name="Test" id="test" type="hidden" />
                    <input name="uid" id="uid" type="hidden" />
                    <input name="pwd" id="pwd" type="hidden" />
                    <input name="spro" id="spro" type="hidden" />
                    <input name="scity" id="scity" type="hidden" />
                    <input name="scou" id="scou" type="hidden" />
                    <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
                </div>
                <div class="fitem">
                    <label>用户姓名：</label>
                    <input id="utruename" name="utruename" class="easyui-validatebox" data-options="required:true,validType:'CHS'" />
                </div>
                <div class="fitem">
                    <label>手机：</label>
                    <input id="uphone" name="uphone" class="easyui-validatebox" data-options="required:true,validType:'mobile'" />
                </div>
                <div class="fitem">
                    <label>邮箱：</label>
                    <input id="uemail" name="uemail" class="easyui-validatebox" data-options="required:true,validType:'email'" />
                </div>
                <div class="fitem">
                    <label>单位：</label>
                    <input id="uunit" name="uunit" class="easyui-validatebox" data-options="required:true" />
                </div>
                <div class="fitem">
                    <label>单位电话：</label>
                    <input id="utel" name="utel" class="easyui-validatebox" />
                </div>
                <div class="fitem">
                    <label>级别：</label>
                    <input id="ulevel" name="ulevel" style="width: 150px;" />                        
                    
                </div>
                <div class="fitem" >
                <label>职务：</label>
                <input id="pid" name="pid" class="easyui-combobox" />
            </div>  
                <div class="fitem" id="dprovince">
                    <label>省：</label>
                    <input id="uprovince" name="uprovince" class="easyui-combobox" />
                </div>
                <div class="fitem" id="dcity">
                    <label>市：</label>
                    <input id="ucity" name="ucity" class="easyui-combobox" />
                </div>
                <div class="fitem" id="dcounty">
                    <label>县：</label>
                    <input id="ucounty" name="ucounty" class="easyui-combobox" />
                </div>
                <div class="fitem">
                    <label>地址：</label>
                    <input id="uadd" name="uadd" class="easyui-validatebox" />
                </div>

                <div class="fitem">
                    <label>小气候：</label>
                    <input id="remark" name="remark" style="width: 150px;" />
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
        </div>
    </div>
</asp:Content>

